/**
  *@File文件:ShopBillController.java
  *@Date日期:2017年7月20日 下午6:38:36
  *@Copyright版权:Corporation 2017
  */
package com.qiaomengapp.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.qiaomengapp.bean.ShopBillWrapper;
import com.qiaomengapp.bean.User;
import com.qiaomengapp.exception.CustomException;
import com.qiaomengapp.service.IShopBillService;

/**
 *@Description描述:
 *@Author作者 wangzongwen
 *@Date日期:2017年7月20日
 */
@Controller
@RequestMapping("shopBill/api")
public class ShopBillController {
	
	@Autowired
	private IShopBillService iShopBillService;
	
	/**
	 *@Description描述:  查询信息
	 *@param session 域对象
	 *@param type 信息类型
	 *@return
	 *@return List<ShopBillWrapper> 查询到的信息集合
	 */
	@RequestMapping("/selectShopBillWrapper")
	@ResponseBody
	public Object selectShopBillWrapper(HttpSession session, Integer type){
		//得到用户对象
		User user = (User) session.getAttribute("user");
		if (user==null) {
			user = new User();
			user.setId(1);
		}
		try {
			List<ShopBillWrapper> list = iShopBillService.selectShopBillWrapper(user.getId(), type);
			return list;
		} catch (CustomException e) {
			e.printStackTrace();
			//向前端发送错误信息
			Map<String, String> map = new HashMap<String,String>();
			map.put("error", e.getMessage());
			return map;
		}
	}
	
	@RequestMapping("/selectShopBillCount")
	@ResponseBody
	public Object selectShopBillCount(HttpSession session) {
		//查询商铺信息
		User user = (User) session.getAttribute("user");
		int count = iShopBillService.selectShopBillCount(user.getId());
		//把数据保存到map集合中
		Map<String, Integer> map = new HashMap<String,Integer>();
		map.put("count", count);
		return map;
	}
	
}
